package com.intranet.sys.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.intranet.sys.dao.UserDao;
import com.intranet.sys.domain.User;
import com.water.dao.Page;

@Service
public class UserService {

	@Autowired
	private UserDao userDao;

	/**
	 * 查询所有用户
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public Page getAllUser(int pageNo, int pageSize, String param) {
		return userDao.queryUserList(pageNo, pageSize, param);
	}

	/**
	 * 登陆用户名查询用户
	 * 
	 * @param username
	 * @return
	 */
	public User getUserByUserName(String username) {
		return userDao.getUserByUserName(username);
	}

	/**
	 * 登陆用户名查询用户
	 * 
	 * @param username
	 * @return
	 */
	public boolean findUserByUserName(String username) {
		boolean b = false;
		User u = userDao.getUserByUserName(username);
		if (u != null) {
			b = true;
		} else {
			b = false;
		}
		return b;
	}

	public String saveUser(User user) {
		String msg = "";
		try {
			userDao.save(user);
			msg = "Y";
		} catch (RuntimeException e) {
			msg = e.toString();
		}
		return msg;
	}

	public String updateUser(User user) {
		String msg = "";
		try {
			userDao.update(user);
			msg = "Y";
		} catch (RuntimeException e) {
			msg = e.toString();
		}
		return msg;
	}

	public String deleteUser(User user) {
		String msg = "";
		try {
			userDao.remove(user);
			msg = "Y";
		} catch (RuntimeException e) {
			msg = "N";
		}
		return msg;
	}

	public User getUserById(Integer id) {
		return userDao.get(id);
	}
}
